<?php

namespace Portal\ContentBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Portal\MainBundle\Utils\customFunctions;

class ContentController extends Controller
{    
    public function showContentAction($title)
    {
      $title = customFunctions::clearForUrl($title);

      $content = $this->getDoctrine()->getEntityManager()->getRepository('PortalContentBundle:Content')->getContentByTitle($title);
      
      if (!$content) {
        $displayContent = $this->renderView(
              'PortalMainBundle:Index:pageNotFound.html.twig', array()
        );

        return new Response($displayContent);
      }
      
      $tableName = $this->container->getParameter('tableNameContent');
      $tableId = $content['id'];
      
      if($content['has_comment'])
      {
        $commentPermission = true;
      }else{
        $commentPermission = false;
      }
      
      return $this->render('PortalContentBundle:Content:showContent.html.twig', array(
                  'content' => $content,
                  'contentId' => $content['id'],
                  'commentPermission' => $commentPermission,
                  'tableName' => $tableName,
                  'tableId' => $tableId,
              ));
    }
}
